<fieldset class="layui-elem-field">
    <form class="layui-form" id="searchForm">
        <e>备份文件列表中共有 <b>{$statistics.count}</b> 个文件，共计 <b>{$statistics.total}</b> </e>
    </form>
</fieldset>
<table class="layui-hide" id="mytable" lay-filter="mytable"></table>

<script type="text/html" id="optbar">
    <a class="layui-btn layui-btn-xs" lay-event="import">还原</a>
    <a class="layui-btn layui-btn-xs" lay-event="downFile">下载</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delSqlFiles">删除</a>
</script>

<script type="text/javascript">
    $(function(){
        ybTable.render({
            elem: '#mytable'
            ,url: "{:url('getRestoreList')}"
            ,where: searchParamObj('searchForm')
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,title: '数据表'
            ,cols: [[
                {field:'name', title: '文件名称'}
                ,{field:'size', title: '文件大小'}
                ,{field:'addtime', title: '备份时间'}
                ,{title: '操作', toolbar: '#optbar', width:200}
            ]]
            ,page: false
            ,response: {
                statusCode: 1 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.dataList //解析数据列表
                };
            }
        });

        //监听行工具事件
        ybTable.on('tool(mytable)',function(obj){
            var data = obj.data;
            if(obj.event === 'import'){
                ybLayer.confirm('确认要还原吗？此操作不可逆！', function(index) {
                    ybLayer.close(index);
                    ajaxPost("{:url('import')}", {'time': data.time}, function (res) {
                        ybLayer.msg(res.msg, {icon: 6});
                        setTimeout(function () {
                            ybTable.reload('mytable');
                        }, 1000);
                    }, function (res) {
                        ybLayer.msg(res.msg, {icon: 5});
                    })
                });
                return false;
            }else if(obj.event === 'downFile'){
                window.location.href = "downFile?time=" + data.time;
                return false;
            }else if(obj.event === 'delSqlFiles'){
                ybLayer.confirm('确认要删除么', function(index){
                    ybLayer.close(index);
                    ajaxPost("{:url('delSqlFiles')}",{'time':data.time},function(res){
                        ybLayer.msg(res.msg,{icon: 6});
                        setTimeout(function () {
                            ybTable.reload('mytable');
                        }, 1000);
                    },function(res){
                        ybLayer.msg(res.msg,{icon: 5});
                    })
                });
                return false;
            }
        });

    })
</script>